<?php
namespace lib;

use lib\rule\ParentInit;
use lib\rule\UtilRouter;

/**
 * Ldy-item-Tools
 * 自动加载
 * Class autoload
 * @package lib
 */
class autoload{

    public function run(){
        spl_autoload_register([$this,'load']);
        $UtilRouter = new UtilRouter();
        return $UtilRouter->_beginInit();
    }

    /**
     * 自动加载
     * @param $class
     */
    public function load($class) {
        $loadArray = explode('\\',$class);
        $class  = implode('/',$loadArray);
//        require __DIR__.DR.'../'.$class.'.php';
        require LIB.DR.'../'.$class.'.php';
    }

    /**
     * 整目录引入
     * @param string $path
     */
    public static function itemLoad($path = LIB){
        $dir = scandir($path);
        foreach ($dir as $value){
            $sub_path =$path.'/'.$value;
            if($value == '.' || $value == '..'){
                continue;
            }else if(is_dir($sub_path)){
                self::itemLoad($sub_path);
            }else{
                if ($value != 'autoload.php'){
                    require $sub_path;
                }
            }
        }
    }

}
